home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
United Public Domain Gold 2
/
United Public Domain Gold 2.iso
/
utilities
/
pu248.dms
/
pu248.adf
/
Intuition
/
Miscellaneous
/
Example2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-01
|
3KB
|
93 lines
/***********************************************************/
/* */
/* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
/* ------------------------------- ------------------ */
/* */
/* Book: ACM Intuition Amiga C Club */
/* Chapter: Miscellaneous Tulevagen 22 */
/* File: Example2.c 181 41 LIDINGO */
/* Author: Anders Bjerin SWEDEN */
/* Date: 92-05-01 */
/* Version: 1.10 */
/* */
/* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
/* */
/* Registered members may use this program freely in their */
/* own commercial/noncommercial programs/articles. */
/* */
/***********************************************************/
/* This example shows how to allocate and deallocate memory with help of */
/* the functions AllocRemember(), and FreeRemember(). */
#include <intuition/intuition.h>
#include <exec/memory.h>
struct IntuitionBase *IntuitionBase;
main()
{
/* Declare and initialize a pointer to the first Remember structure: */
struct Remember *remember = NULL;
/* Declare three memory pointers: */
CPTR memory1, memory2, memory3;
/* Open the Intuition Library: */
IntuitionBase = (struct IntuitionBase *)
OpenLibrary( "intuition.library", 0 );
if( IntuitionBase == NULL )
exit(); /* Could NOT open the Intuition Library! */
/* Allocate 350 bytes of Chip memory, which is cleared: */
memory1 = AllocRemember( &remember, 350, MEMF_CHIP|MEMF_CLEAR );
if( memory1 == NULL )
{
CloseLibrary( IntuitionBase );
exit();
}
/* Allocate 900 bytes of memory (any type, Fast if possible): */
memory2 = AllocRemember( &remember, 900, MEMF_PUBLIC );
if( memory2 == NULL )
{
FreeRemember( &remember, TRUE );
CloseLibrary( IntuitionBase );
exit();
}
/* Allocate 100 bytes of Chip memory: *
memory3 = AllocRemember( &remember, 100, MEMF_CHIP );
if( memory3 == NULL )
{
FreeRemember( &remember, TRUE );
CloseLibrary( IntuitionBase );
exit();
}
/* Do whatever you want to do with the memory. */
/* Deallocate all memory with one single call: */
FreeRemember( &remember, TRUE );
/* Close the Intuition Library: */
CloseLibrary( IntuitionBase );
}